package com.design02_Structural.pattern08_decorator;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

/**
 * @ClassName BaseFileDataLoader
 * @Description TODO
 * @Author zhangjunhao
 * @DATE 2023/9/4 23:26
 */
public class BaseFileDataLoader implements DataLoader  {

    private String filePath;

    public BaseFileDataLoader(String filePath) {
        this.filePath = filePath;
    }

    @Override
    public String read() {
        try {
            FileUtils.readFileToString(new File(filePath),"utf-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void write(String data) {

        try {
            FileUtils.writeStringToFile(new File(filePath),data,"utf-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
